import Vue from 'vue'
import Router from 'vue-router'

import Home from '@/components/Home'
import Login from '@/components/Login'
import PageNotFound from '@/components/error/404.vue'

import UserContribute from '@/components/recharge/UserContribute'
import OnlineRecharge from '@/components/recharge/OnlineRecharge'
import OnlineRechargeHistory from '@/components/recharge/OnlineRechargeHistory'
import UserContributeHistory from '@/components/recharge/UserContributeHistory'
import AllContributeHistory from '@/components/recharge/AllContributeHistory'

import UserDetail from '@/components/userinfo/UserDetail'
import NewUserDetail from '@/components/userinfo/NewUserDetail'
import UserInfo from '@/components/userinfo/UserInfo'
import Me from '@/components/userinfo/Me'
import GetYuanBao from '@/components/userinfo/GetYuanBao'
import NewUserNumHistory from '@/components/userinfo/NewUserNumHistory'
import NewAdUserNumHistory from '@/components/userinfo/NewAdUserNumHistory'

import AgentContributeDetail from '@/components/agent/AgentContributeDetail'
import AgentContributeDetailHistory from '@/components/agent/AgentContributeDetailHistory'
import AgentDetail from '@/components/agent/AgentDetail'
import NewAgentDetail from '@/components/agent/NewAgentDetail'
import AgentScore from '@/components/agent/AgentScore'
import AgentYunyin from '@/components/agent/AgentYunyin'
import AgentInfo from '@/components/agent/AgentInfo'
import AgentData from '@/components/agent/AgentData'
import AgentNextContribute from '@/components/agent/AgentNextContribute'
import AgentNextContributeHistory from '@/components/agent/AgentNextContributeHistory'
import AgentExpandHistory from '@/components/agent/AgentExpandHistory'
import NewAgentNumHistory from '@/components/agent/newAgentNumHistory'

import CodeMenu from '@/components/menu/CodeMenu'
import ContributeMenu from '@/components/menu/ContributeMenu'
import AgentMenu from '@/components/menu/AgentMenu'
import UserMenu from '@/components/menu/UserMenu'
import CarrieroperatorMenu from '@/components/menu/CarrieroperatorMenu'

import AuthMenu from '@/components/menu/AuthMenu'
import AboutMe from '@/components/menu/AboutMe'
import GmMenu from '@/components/menu/GmMenu'
import AgentInfoMenu from '@/components/menu/AgentInfoMenu'
import ScoreMenu from '@/components/menu/ScoreMenu'
import BossCaMenu from '@/components/menu/BossCaMenu'

import CreateGM from '@/components/GM/CreateGM'
import UpdateShareCode from '@/components/GM/UpdateShareCode'
import UpdateDivision from '@/components/GM/UpdateDivision'
import Closure from '@/components/GM/Closure'
import Warning from '@/components/GM/Warning'
import Give from '@/components/GM/Give'
import Sign from '@/components/GM/Sign'
import Vip from '@/components/GM/Vip'
import Robot from '@/components/GM/Robot'
import AddRobot from '@/components/GM/AddRobot'

import CarrieroperatorScore from '@/components/carrieroperator/CarrieroperatorScore'
import CarrieroperatorScoreHistory from '@/components/carrieroperator/CarrieroperatorScoreHistory'

import BossScore from '@/components/boss/BossScore'
import BossScoreHistory from '@/components/boss/BossScoreHistory'
import BossCaAgent from '@/components/boss/BossCaAgent'
import BossCaUser from '@/components/boss/BossCaUser'
import BossCaInfo from '@/components/boss/BossCaInfo'

import CreateCodeDetail from '@/components/code/CreateCodeDetail'
import UseCodeDetail from '@/components/code/UseCodeDetail'

import AuditInformation from '@/components/auth/AuditInformation'
import AuthLog from '@/components/auth/AuthLog'

import Menu from '@/components/admin/Menu'
import RoleMenu from '@/components/admin/RoleMenu'
import Maintenance from '@/components/admin/Maintenance'
import Admin from '@/components/Admin'

import Chart from '@/components/component/Chart'

Vue.use(Router)

const router = new Router({
  routes: [
    {path: '/', name: 'Login', component: Login},
    {path: '/home', name: 'Home', component: Home},
    {path: '/404', name: 'PageNotFound', component: PageNotFound},
    {path: '/admin', name: 'Admin', component: Admin},

    {path: '/recharge/userContribute', name: 'UserContribute', component: UserContribute},
    {path: '/recharge/onlineRecharge', name: 'OnlineRecharge', component: OnlineRecharge},
    {path: '/recharge/onlineRechargeHistory', name: 'OnlineRechargeHistory', component: OnlineRechargeHistory},
    {path: '/recharge/userContributeHistory', name: 'UserContributeHistory', component: UserContributeHistory},
    {path: '/recharge/allContributeHistory', name: 'AllContributeHistory', component: AllContributeHistory},

    {path: '/user/userDetail', name: 'UserDetail', component: UserDetail},
    {path: '/user/newUserDetail', name: 'NewUserDetail', component: NewUserDetail},
    {path: '/user/userInfo', name: 'UserInfo', component: UserInfo},
    {path: '/user/me', name: 'Me', component: Me},
    {path: '/user/getYuanBao', name: 'GetYuanBao', component: GetYuanBao},
    {path: '/user/newUserNumHistory', name: 'NewUserNumHistory', component: NewUserNumHistory},
    {path: '/user/newAdUserNumHistory', name: 'NewAdUserNumHistory', component: NewAdUserNumHistory},

    {path: '/agent/agentContributeDetail', name: 'AgentContributeDetail', component: AgentContributeDetail},
    {path: '/agent/agentContributeDetailHistory', name: 'AgentContributeDetailHistory', component: AgentContributeDetailHistory},
    {path: '/agent/agentDetail', name: 'AgentDetail', component: AgentDetail},
    {path: '/agent/newAgentDetail', name: 'NewAgentDetail', component: NewAgentDetail},
    {path: '/agent/agentScore', name: 'AgentScore', component: AgentScore},
    {path: '/agent/agentYunyin', name: 'AgentYunyin', component: AgentYunyin},
    {path: '/agent/agentInfo', name: 'AgentInfo', component: AgentInfo},
    {path: '/agent/agentData', name: 'AgentData', component: AgentData},
    {path: '/agent/agentNextContribute', name: 'AgentNextContribute', component: AgentNextContribute},
    {path: '/agent/agentNextContributeHistory', name: 'AgentNextContributeHistory', component: AgentNextContributeHistory},
    {path: '/agent/agentExpandHistory', name: 'AgentExpandHistory', component: AgentExpandHistory},
    {path: '/agent/newAgentNumHistory', name: 'NewAgentNumHistory', component: NewAgentNumHistory},

    {path: '/menu/codeMenu', name: 'CodeMenu', component: CodeMenu},
    {path: '/menu/contributeMenu', name: 'ContributeMenu', component: ContributeMenu},
    {path: '/menu/agentMenu', name: 'AgentMenu', component: AgentMenu},
    {path: '/menu/userMenu', name: 'UserMenu', component: UserMenu},
    {path: '/menu/carrieroperatorMenu', name: 'CarrieroperatorMenu', component: CarrieroperatorMenu},
    {path: '/menu/gameMenu', name: 'Chart', component: Chart},
    {path: '/menu/authMenu', name: 'AuthMenu', component: AuthMenu},
    {path: '/menu/aboutMe', name: 'AboutMe', component: AboutMe},
    {path: '/menu/gmMenu', name: 'GmMenu', component: GmMenu},
    {path: '/menu/agentInfoMenu', name: 'AgentInfoMenu', component: AgentInfoMenu},
    {path: '/menu/scoreMenu', name: 'ScoreMenu', component: ScoreMenu},
    {path: '/menu/bossCaMenu', name: 'BossCaMenu', component: BossCaMenu},

    {path: '/gm/createGM', name: 'CreateGM', component: CreateGM},
    {path: '/gm/updateShareCode', name: 'UpdateShareCode', component: UpdateShareCode},
    {path: '/gm/closure', name: 'Closure', component: Closure},
    {path: '/gm/warning', name: 'Warning', component: Warning},
    {path: '/gm/updateDivision', name: 'UpdateDivision', component: UpdateDivision},
    {path: '/gm/give', name: 'Give', component: Give},
    {path: '/gm/sign', name: 'Sign', component: Sign},
    {path: '/gm/vip', name: 'Vip', component: Vip},
    {path: '/gm/robot', name: 'Robot', component: Robot},
    {path: '/gm/addRobot', name: 'AddRobot', component: AddRobot},

    {path: '/score/bossScore', name: 'BossScore', component: BossScore},
    {path: '/score/bossScoreHistory', name: 'BossScoreHistory', component: BossScoreHistory},
    {path: '/bossca/agent', name: 'BossCaAgent', component: BossCaAgent},
    {path: '/bossca/user', name: 'BossCaUser', component: BossCaUser},
    {path: '/bossca/cainfo', name: 'BossCaInfo', component: BossCaInfo},

    {path: '/code/createCodeDetail', name: 'CreateCodeDetail', component: CreateCodeDetail},
    {path: '/code/useCodeDetail', name: 'UseCodeDetail', component: UseCodeDetail},

    {path: '/carrieroperator/carrieroperatorScore', name: 'CarrieroperatorScore', component: CarrieroperatorScore},
    {path: '/carrieroperator/carrieroperatorScoreHistory', name: 'CarrieroperatorScoreHistory', component: CarrieroperatorScoreHistory},

    {path: '/auth/auditInformation', name: 'AuditInformation', component: AuditInformation},
    {path: '/auth/authLog', name: 'AuthLog', component: AuthLog},

    {path: '/admin/menu', name: 'Menu', component: Menu},
    {path: '/admin/roleMenu', name: 'RoleMenu', component: RoleMenu},
    {path: '/admin/maintenance', name: 'Maintenance', component: Maintenance}
  ]
})

router.beforeEach((to, from, next) => {
  if (to.path === '/' || to.path === '/404' || to.path === '/admin') {
    next()
  } else {
    let menus = JSON.parse(sessionStorage.getItem('menu'))
    if (menus === null) {
      next('/')
    } else {
      for (let menu in menus) {
        if (menus[menu].url === to.path) {
          next()
          return false
        }
      }
      console.log('no menu')
      next({path: '/404'})
    }
  }
})

export default router
